#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <linux/limits.h>
#include <unistd.h>
#include <attr/xattr.h>
#include <sqlite3.h>
#include "fscontroller.h"
#include "fslayer.h"

using namespace std;

class TinyVCS : public FSLayer {
	public:
	TinyVCS() {
		this->ppDb = NULL;
	}
	~TinyVCS() {
		if(this->ppDb)
			sqlite3_close(this->ppDb);
	}
	int init_plugin() {
		const char *data_dir = controller->getDataDir();
		const char *slash = "/";
		const char *filename = "vcs.sqlite";
		char *db = malloc(strlen(data_dir) + strlen(slash) + strlen(filename));
		strcpy(db, data_dir);
		strcat(db, slash);
		strcat(db, filename);
		if(sqlite3_open(db, &(this->ppDb)) != SQL_OK) {
			const char *sql_error = sqlite3_errmsg(ppDb);
			sprintf(this->err_str, "mod_vcs error: %s", sql_error);
			controller->error(this->err_str);
			return -1;
		}
		return 0;
	}
	private:
	sqlite3 *ppDb;
}
